<template>
  <div class="qun-list">
    <div class="readcrumb">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>提交申请</el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <!--添加-->
      <el-form :model="form" :rules="rules" ref="form" label-width="150px" class="demo-ruleForm">

        <el-form-item label="标题" prop="title">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="经费" prop="funds">
          <el-input  v-model="form.funds"></el-input>
        </el-form-item>
        <el-form-item label="部门" prop="department_id">
          <el-input  v-model="form.department_id"></el-input>
        </el-form-item>
        <el-button type="primary" @click="addSubmit()" id="add-btn">添加</el-button>
      </el-form>

  </div>
</template>

<script>
  import {fundsAdd} from '@/api';

  export default {
    name: 'fundsAdd',
    data () {
      return {
        // 经费
        form: {
          id: 0,
          title: '',
          funds_num: '',
          fundsting_num: '',
          output_num: ''
        },
        rules: {
          year: [
            {required: true, message: '请输入年度', trigger: 'blur'}
          ],
          funds_num: [
            {required: true, message: '请输入计划数量', trigger: 'blur'}
          ],
          fundsting_num: [
            {required: true, message: '请输入实际养殖数量', trigger: 'blur'}
          ],
          output_num: [
            {required: true, message: '请输入产出数量', trigger: 'blur'}
          ]
        }
      };
    },

    methods: {
      addSubmit () {
        this.$refs.form.validate((valid) => {
          var btn = document.getElementById('add-btn');
          btn.disabled = true;// 禁用提交按钮

          if (valid) {
            this.$http.post(fundsAdd, this.form).then(response => {
              if (response.data.status === 1) {
                this.$message.success('保存成功');
                btn.disabled = false;
                this.$router.go(-1);
              } else {
                this.$message.error('保存失败');
              }
            }).catch(error => {
              btn.disabled = false;
              this.$message.error('删除失败');
              console.log(error);
            });
          } else {
            btn.disabled = false;
            console.log('error submit!!');
            return false;
          }
        });
      }

    }
  };
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.demo-ruleForm{width:500px}
  #add-btn{
    margin-left:200px;}
</style>
